using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using Nop.Core;
using Nop.Core.Caching;
using Nop.Core.Data;
using Nop.Core.Domain.Catalog;
using Nop.Core.Domain.Common;
using Nop.Core.Domain.Localization;
using Nop.Core.Domain.Orders;
using Nop.Services.Events;
using Nop.Data;
using Nop.Services.Localization;
using Nop.Services.Messages;

namespace Nop.Services.Catalog
{
    /// <summary>
    /// Product service
    /// </summary>
    public partial class ProductService : IProductService
    {

        private readonly IRepository<ProductCategory> _productCategoryRepository;

        public ProductService(ICacheManager cacheManager,
            IRepository<Product> productRepository,
            IRepository<ProductVariant> productVariantRepository,
            IRepository<RelatedProduct> relatedProductRepository,
            IRepository<CrossSellProduct> crossSellProductRepository,
            IRepository<TierPrice> tierPriceRepository,
            IRepository<ProductPicture> productPictureRepository,
            IRepository<LocalizedProperty> localizedPropertyRepository,
            IRepository<ProductSpecificationAttribute> productSpecificationAttributeRepository,
            IProductAttributeService productAttributeService,
            IProductAttributeParser productAttributeParser,
            ILanguageService languageService,
            IWorkflowMessageService workflowMessageService,
            IDataProvider dataProvider, IDbContext dbContext,
            LocalizationSettings localizationSettings, CommonSettings commonSettings,
            IEventPublisher eventPublisher, IRepository<ProductCategory> productCategoryRepository)
                {
                    this._cacheManager = cacheManager;
                    this._productRepository = productRepository;
                    this._productVariantRepository = productVariantRepository;
                    this._relatedProductRepository = relatedProductRepository;
                    this._crossSellProductRepository = crossSellProductRepository;
                    this._tierPriceRepository = tierPriceRepository;
                    this._productPictureRepository = productPictureRepository;
                    this._localizedPropertyRepository = localizedPropertyRepository;
                    this._productSpecificationAttributeRepository = productSpecificationAttributeRepository;
                    this._productAttributeService = productAttributeService;
                    this._productAttributeParser = productAttributeParser;
                    this._languageService = languageService;
                    this._workflowMessageService = workflowMessageService;
                    this._dataProvider = dataProvider;
                    this._dbContext = dbContext;
                    this._localizationSettings = localizationSettings;
                    this._commonSettings = commonSettings;
                    this._eventPublisher = eventPublisher;
                    this._productCategoryRepository = productCategoryRepository;
                }

        #region Methods

        #region Products

        /// <summary>
        /// Get products by identifiers
        /// </summary>
        /// <param name="productIds">Product identifiers</param>
        /// <returns>Products</returns>
        public virtual IList<Product> GetProductsByCategoryId(int categoryId)
        {
            if (categoryId == null )
                return new List<Product>();

            var query = from p in _productRepository.Table
                        from pc in p.ProductCategories.Where(pc => categoryId == pc.CategoryId)
                        select p;
            var products = query.ToList();
            return products;
        }

        #endregion


        #endregion
    }
}
